package com.frkj.yuan.api.presenter;

import com.frkj.yuan.api.bean.HospitalBean;
import com.frkj.yuan.api.bean.HospitalPoiListBean;
import com.frkj.yuan.api.bean.NearPeizhenPerson;
import com.frkj.yuan.api.bean.OrderDetialsBean;
import com.frkj.yuan.api.category.HospitalPoiCategory;
import com.frkj.yuan.main.ConstantStaticUrl;
import com.frkj.yuan.utils.RetrofitUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 信息说明:
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/4/19 21 ：13
 * 项目名称：yuanban
 */
public class HospitalPoiPresenter implements HospitalPoiCategory.Presenter {
    HospitalPoiCategory.View view;

    public HospitalPoiPresenter(HospitalPoiCategory.View view) {
        this.view = view;
    }

    @Override
    public void getOrderDeials(String mToken, String orderId) {
        RetrofitUtil.getInstance().getmService().get_map_States(mToken,orderId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    OrderDetialsBean userInfor = gson.fromJson(result, OrderDetialsBean.class);
                    view.getOrderDeials(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
    @Override
    public void getHospitalPoiList( long hospitalId) {
        RetrofitUtil.getInstance().getmService().getHospitalPoiList(hospitalId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    HospitalPoiListBean userInfor = gson.fromJson(result, HospitalPoiListBean.class);
                    view.getHospitalPoiList(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });

    }

    @Override
    public void getNearPeizhen(String latitude, String longitude) {
        RetrofitUtil.getInstance().getmService().getNearPeizhen(latitude,longitude).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    NearPeizhenPerson userInfor = gson.fromJson(result, NearPeizhenPerson.class);
                    view.getNearPeizhen(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
}
